<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="${basePackage}.${moduleName}.dao.${table.className}PoMapper" >
  <resultMap id="BaseResultMap" type="${basePackage}.bean.po.${table.className}Po" >
  <#list table.primaryKeys as key>
	<id column="${key.columnName}" property="${key.javaProperty}" jdbcType="${key.jdbcTypeName}" />
  </#list>
  <#list table.baseColumns as column>
  	<#if column.columnName == "CREATER_ID">
  	<#elseif column.columnName == "UPDATER_ID">
  	<#else>
  	<result column="${column.columnName}" property="${column.javaProperty}" jdbcType="${column.jdbcTypeName}" />
  	</#if>  
  </#list>
  	<association property="creater" columnPrefix="creater_" resultMap="net.feimz.security.dao.SysUserDao.sysUserName" />
  	<association property="updater" columnPrefix="updater_" resultMap="net.feimz.security.dao.SysUserDao.sysUserName" />
  </resultMap>
${r'
  <sql id="Example_Where_Clause4Page" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
      and mainTable.flag = ${@net.common.bean.Flag@getNormalVal()}
	  and (mainTable.PUBLIC_DATA = 1 or mainTable.creater_id= ${@net.feimz.security.utils.ShiroUtils@getUserId()})
       
    </where>
  </sql>

  <sql id="Example_Where_Clause" >
    <where >
      <foreach collection="oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
    </where>
      and mainTable.flag = ${@net.common.bean.Flag@getNormalVal()}
	  and (mainTable.PUBLIC_DATA = 1 or mainTable.creater_id= ${@net.feimz.security.utils.ShiroUtils@getUserId()})
       
  </sql>
  <sql id="Update_By_Example_Where_Clause" >
    <where >
      <foreach collection="example.oredCriteria" item="criteria" separator="or" >
        <if test="criteria.valid" >
          <trim prefix="(" suffix=")" prefixOverrides="and" >
            <foreach collection="criteria.criteria" item="criterion" >
              <choose >
                <when test="criterion.noValue" >
                  and ${criterion.condition}
                </when>
                <when test="criterion.singleValue" >
                  and ${criterion.condition} #{criterion.value}
                </when>
                <when test="criterion.betweenValue" >
                  and ${criterion.condition} #{criterion.value} and #{criterion.secondValue}
                </when>
                <when test="criterion.listValue" >
                  and ${criterion.condition}
                  <foreach collection="criterion.value" item="listItem" open="(" close=")" separator="," >
                    #{listItem}
                  </foreach>
                </when>
              </choose>
            </foreach>
          </trim>
        </if>
      </foreach>
      and flag = ${@net.common.bean.Flag@getNormalVal()}
	  and (mainTable.PUBLIC_DATA = 1 or mainTable.creater_id= ${@net.feimz.security.utils.ShiroUtils@getUserId()})
    </where>
  </sql>'}
  
  <sql id="Base_Column_List" >
    <#list table.columns as column>
    <#if column_has_next>
	${r'${alias}'}.${column.columnName},
	<#else>
	${r'${alias}'}.${column.columnName}
	</#if>
  	</#list>
  </sql>
  
  <sql id="Limit_Column_List" >
    <#list table.columns as column>
    <#if column_has_next>
	${r"${alias}"}.${column.columnName} ${r" as '${prefix}"}${column.columnName}${r"'"},
	<#else>
	${r"${alias}"}.${column.columnName} ${r" as '${prefix}"}${column.columnName}${r"'"}
	</#if>
  	</#list>
  </sql>
  
  <select id="selectByExample" resultMap="BaseResultMap" >
    select
    <if test="example.distinct" >
      distinct
    </if>
    'true' as QUERYID,
    <include refid="Base_Column_List" >
    	<property name="alias" value="mainTable"/>
    </include>,
    <include refid="net.feimz.security.dao.SysUserDao.User_Limit_Column_List">
    	<property name="prefix" value="creater_"/>
    	<property name="alias" value="creater"/>
    </include>,
    <include refid="net.feimz.security.dao.SysUserDao.User_Limit_Column_List">
    	<property name="prefix" value="updater_"/>
    	<property name="alias" value="updater"/>
    </include>    
    from ${table.tableName} mainTable
    left join sys_user creater on creater.USER_ID = mainTable.CREATER_ID
    left join sys_user updater on updater.USER_ID = mainTable.UPDATER_ID
        
    <if test="example.oredCriteria != null" >
      <include refid="Example_Where_Clause4Page" />
    </if>
    <if test="example.orderByClause != null" >
      order by ${r'${example.orderByClause}'}
    </if>
  </select>
  
  <select id="selectByKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
    select 
    <include refid="Base_Column_List" >
    	<property name="alias" value="mainTable"/>
    </include>,
    <include refid="net.feimz.security.dao.SysUserDao.User_Limit_Column_List">
    	<property name="prefix" value="creater_"/>
    	<property name="alias" value="creater"/>
    </include>,
    <include refid="net.feimz.security.dao.SysUserDao.User_Limit_Column_List">
    	<property name="prefix" value="updater_"/>
    	<property name="alias" value="updater"/>
    </include>
    from ${table.tableName} mainTable
    left join sys_user creater on creater.USER_ID = mainTable.CREATER_ID
    left join sys_user updater on updater.USER_ID = mainTable.UPDATER_ID    
    where mainTable.id = ${r'#{id,jdbcType=INTEGER}'}
    and mainTable.flag = ${r'${@net.common.bean.Flag@getNormalVal()}'}
  </select>
  
  <insert id="insert" parameterType="${basePackage}.bean.po.${table.className}Po" >
    insert into ${table.tableName} (
    <#list table.columns as column>
    <#if column_has_next>
	${column.columnName},
	<#else>
	${column.columnName}
	</#if>
  	</#list>    
    )
    values (
    <#list table.columns as column>
	    <#if column_has_next>
		${r'#{'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}},
		<#else>
		${r'#{'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}}
		</#if>
  	</#list>
	)
  </insert>
  
  <select id="countByExample" parameterType="net.common.bean.BasePoExample" resultType="java.lang.Integer" >
    select count(*) from ${table.tableName}
    <if test="_parameter != null" >
      <include refid="Example_Where_Clause" />
    </if>
  </select>
  <update id="updateByExampleSelective" parameterType="map" >
    update ${table.tableName} mainTable
    <set>
    <#list table.columns as column>
	    <#if column_has_next>
      ${r'<if test="record.'}${column.javaProperty} != null" >
        ${column.columnName}=${r'#{record.'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}},
      ${r'</if>'}
		<#else>
      ${r'<if test="record.'}${column.javaProperty} != null" >
        ${column.columnName}=${r'#{record.'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}}
      ${r'</if>'}
		</#if>
  	</#list>
    </set>
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <!-- 不更新creater_id 和 create_time -->
  <update id="updateByExample" parameterType="map" >
    update ${table.tableName} mainTable
    set 
     <#list table.columns as column>
       	<#if column.columnName == "CREATER_ID">
	  	<#elseif column.columnName == "CREATE_TIME">
	  	<#else>
	    	<#if column_has_next>
        ${column.columnName}=${r'#{record.'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}},
			<#else>
		${column.columnName}=${r'#{record.'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}}
			</#if>
		</#if>
  	</#list>   
    <if test="_parameter != null" >
      <include refid="Update_By_Example_Where_Clause" />
    </if>
  </update>
  <update id="updateByKeySelective" parameterType="${basePackage}.bean.po.${table.className}Po" >
    update ${table.tableName} mainTable
    <set>
    <#list table.baseColumns as column>
       	<#if column.columnName == "CREATER_ID">
	  	<#elseif column.columnName == "CREATE_TIME">
	  	<#else>    
	    	<#if column_has_next>
      ${r'<if test="'}${column.javaProperty} != null" >
        ${column.columnName}=${r'#{'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}},
      ${r'</if>'}
			<#else>
      ${r'<if test="'}${column.javaProperty} != null" >
        ${column.columnName}=${r'#{'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}}
      ${r'</if>'}
			</#if>
		</#if>
  	</#list>    
    </set>
    where 1=1 
    <#list table.primaryKeys as column>
	    <#if column_has_next>
       and mainTable.${column.columnName}=${r'#{'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}},
		<#else>
       and mainTable.${column.columnName}=${r'#{'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}}
		</#if>
  	</#list>
  	and mainTable.flag = ${r'${@net.common.bean.Flag@getNormalVal()}'}
  </update>
  <update id="updateByKey" parameterType="${basePackage}.bean.po.${table.className}Po" >
    update ${table.tableName} mainTable
    <set>
 	<#list table.baseColumns as column>
       	<#if column.columnName == "CREATER_ID">
	  	<#elseif column.columnName == "CREATE_TIME">
	  	<#else>  	
	    	<#if column_has_next>
        mainTable.${column.columnName}=${r'#{'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}},
			<#else>
        mainTable.${column.columnName}=${r'#{'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}}
			</#if>
		</#if>
  	</#list>    
    </set>
    where 1=1 
    <#list table.primaryKeys as column>
	    <#if column_has_next>
        and mainTable.${column.columnName}=${r'#{'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}},
		<#else>
        and mainTable.${column.columnName}=${r'#{'}${column.javaProperty}${r',jdbcType='}${column.jdbcTypeName}}
		</#if>
  	</#list>
  	and mainTable.flag = ${r'${@net.common.bean.Flag@getNormalVal()}'}
  </update>
</mapper>